/**
 * @param {string} s
 * @param {string} t
 * @return {character}
 */
// 哈希解法
var findTheDifference = function(s, t) {

    // 新建一个哈希map
    let map  = new Map()

    for (let i = 0; i < s.length; i++) {
        const val = map.get(s[i])
        map.set(s[i], val == undefined ? 1: val + 1)
    }
    for (let j = 0; j < t.length; j++) {
        const val = map.get(t[j])
        if (val == 0 || val == undefined) {
            return t[j]
        }else {
            map.set(t[j], val - 1)
        }
    }
};

// 字母的和计算
var findTheDifference = function(s, t) {
    let s_sum = 0
    let t_sum = 0
    for (let i = 0; i < s.length; i++) {
        s_sum += s[i].charCodeAt()
    }
    // return sum
    for (let j = 0; j < t.length; j++) {
        t_sum += t[j].charCodeAt()
    }
    return String.fromCharCode(t_sum - s_sum)
}

// 位运算
var findTheDifference = function(s, t) {
    let ret = 0
    for (const ch of s) {
        ret ^= ch.charCodeAt();
    }
    for (const ch of t) {
        ret ^= ch.charCodeAt();
    }
    return String.fromCharCode(ret)
}


let s = 'abcd'
let t = 'abcde'
console.log(findTheDifference(s,t))